var e = getApp(), t = require("../../utils/api"), a = require("../../utils/config"), i = require("../../utils/request");

Page({
    data: {
        active: 0,
        themeColor: e.globalData.themeColor,
        sticky: !0,
        swipeable: !0,
        detailUrl: "../../pages/course-detais/course-detais",
        tabs: [],
        phoneHeight: 1e3,
        pageIndex: 1,
        pageSize: 6,
        totalSize: 0,
        articles: [],
        showDivder: !1
    },
    onLoad: function(e) {
        this.selectWcaIndexLinkCourseAll(), this.getPhoneHeight(), this.setData({
            active: null == e.type ? 0 : parseInt(e.type)
        }), 0 == this.data.active && this.selectWcaCourseArticleDtoByPage();
    },
    onTabChange: function(e) {
        this.setData({
            active: e.detail.name,
            articles: [],
            pageIndex: 1,
            showDivder: !1
        }), this.selectWcaCourseArticleDtoByPage(), this.data.articles.length <= 0 && this.setData({
            showDivder: !0
        });
    },
    selectWcaIndexLinkCourseAll: function() {
        var e = this;
        i.request(i.HttpMethod.GET, t.apiRoute.selectIndexWcaCourseCategoryAll, {}).then(function(t) {
            var a = [];
            a.push({
                title: "全部",
                type: 0
            }), "20000" == t.code && t.data.forEach(function(e) {
                a.push({
                    title: e.name,
                    type: parseInt(e.code)
                });
            }), e.setData({
                tabs: a
            });
        });
    },
    getPhoneHeight: function() {
        var e = this;
        wx.getSystemInfo({
            success: function(t) {
                e.setData({
                    phoneHeight: t.windowHeight
                });
            }
        });
    },
    selectWcaCourseArticleDtoByPage: function() {
        var e = this;
        wx.showLoading({
            title: "正在加载中...",
            mask: !0
        });
        var s = "pageIndex=" + this.data.pageIndex + "&pageSize=" + this.data.pageSize + "&categoryCode=" + (0 == this.data.active ? "" : this.data.active);
        i.request(i.HttpMethod.GET, t.apiRoute.selectWcaCourseArticleDtoByPage + s, {}).then(function(t) {
            if ("20000" == t.code) {
                t.data.records.forEach(function(e) {
                    e.coverImageUrl = a.courseCoverImageUrl + e.coverImageUrl;
                });
                var i = e.data.articles.concat(t.data.records);
                e.setData({
                    articles: i,
                    totalSize: t.data.total
                }), wx.hideLoading();
            } else wx.hideLoading();
        });
    },
    onScrollLower: function() {
        var e = this.data.pageIndex + 1;
        (e - 1) * this.data.pageSize > this.data.totalSize ? this.setData({
            showDivder: !0
        }) : (this.setData({
            pageIndex: e
        }), this.selectWcaCourseArticleDtoByPage());
    }
});